const nanoId = require('nanoid'),
      Qiniu = require('qiniu');
module.exports={
    qiniuUpload(options){
        const mac = new Qiniu.auth.digest.Mac(options.ak,options.sk),
              conf = new Qiniu.conf.Config(),
              client = new Qiniu.rs.BucketManager(mac,conf),
              key = nanoId()+options.ext;
        return new Promise((resolve,reject)=>{
            client.fetch(options.url,options.bucket,key,(error,ret,info)=>{
                if(error){
                    reject(error);
                }else{
                    if(info.statusCode === 200){
                        resolve({key})
                    }else{
                        reject(info)
                    }
                }
            })
        })      
    }
}     